import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# 创建网格数据
x1 = np.linspace(-10, 10, 100)
x2 = np.linspace(-10, 10, 100)
X1, X2 = np.meshgrid(x1, x2)

# 计算函数值
Y = X1**2 + X2**2

# 创建图形和轴
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# 绘制曲面
ax.plot_surface(X1, X2, Y, cmap='viridis')

# 设置标签
ax.set_xlabel('x1')
ax.set_ylabel('x2')
ax.set_zlabel('y')

# 显示图形
plt.show()
